{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# Lesson 03\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目1： 给定用户名列表，输入开头几位字母，程序自动补充用户名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "please input name : A\n",
      "Do you want to find ['Adam', 'Alex', 'Amy']?\n"
     ]
    }
   ],
   "source": [
    "# 补充用户名字，利用切片的例子\n",
    "name = ['Adam','Alex','Amy','Bob','Boom','Candy','Chris','David','Jason','Jasonstatham','Bill'];\n",
    "i_name = input('please input name : ')\n",
    "\n",
    "wname = [];\n",
    "for n in name:\n",
    "    if n[0:len(i_name)] == i_name:\n",
    "        wname.append(n);\n",
    "\n",
    "if len(wname) != 0:\n",
    "    print('Do you want to find %s?'%(wname))\n",
    "else:\n",
    "    print('%s not find'%(i_name))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目2：编写一个函数，给你三个整数a,b,c, 判断能否以它们为三个边长构成三角形。若能，输出YES，否则输出NO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "no\n"
     ]
    }
   ],
   "source": [
    "def func1(a,b,c):\n",
    "    if (a+b)>c and (b+c)>a and (a+c)>b:\n",
    "        return 'yes'\n",
    "    else:\n",
    "        return 'no'\n",
    "\n",
    "\n",
    "print(func1(1,2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "no\n"
     ]
    }
   ],
   "source": [
    "def func2(a,b,c):\n",
    "    if max(a,b,c)<(a+b+c)/2.0:\n",
    "        return 'yes'\n",
    "    else:\n",
    "        return 'no'\n",
    "\n",
    "print(func2(1,2,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## 题目3：编写一个猜数字的程序，人在0-1000范围内设定一个数字让电脑猜，每猜一次人反馈电脑是猜大了或小了，为电脑制定一定策略最快猜到正确数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "# 猜数，机器猜\n",
    "\n",
    "min = 0\n",
    "max = 1000\n",
    "\n",
    "guess_ok_mark = False\n",
    "\n",
    "while not guess_ok_mark:\n",
    "\n",
    "    cur_guess = int((min + max) / 2)\n",
    "    print('I guess:', cur_guess)\n",
    "    human_answer = input('Please tell me big or small:')\n",
    "    if human_answer == 'big':\n",
    "        max = cur_guess\n",
    "    if human_answer == 'small':\n",
    "        min = cur_guess\n",
    "    if human_answer == 'ok':\n",
    "        print('HAHAHA')\n",
    "        guess_ok_mark = True"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
